package permission

import (
	"gohub/pkg/app"
	"gohub/pkg/database"
	"gohub/pkg/paginator"

	"github.com/gin-gonic/gin"
)

func GetRoles(permid string) (Permissions []Permission) {
	database.DB.Where("id", permid).Find(&Permissions)
	return
}

// Get 通过 ID 获取
func Get(idstr string) (PermModel Permission) {
	database.DB.Where("id", idstr).First(&PermModel)
	return
}

func GetAll(menus []string) (Permissions []Permission) {
	database.DB.Where("id IN (?)", menus).Find(&Permissions)
	return
}

// All 获取所有数据
func All() (Permissions []Permission) {
	database.DB.Find(&Permissions)
	return
}

// Paginate 分页内容
func Paginate(c *gin.Context, perPage int) (permissions []Permission, paging paginator.Paging) {
	paginator := paginator.New(c, database.DB.Model(&Permission{}), app.V1URL(database.TableName(&Permission{})))
	paging = paginator.Paginate(&permissions)
	return
}

// func Paginate(c *gin.Context, perPage int) (permissions []Permission, paging paginator.Paging) {
// 	paging = paginator.Paginate(
// 		c,
// 		database.DB.Model(Permission{}),
// 		&permissions,
// 		app.V1URL(database.TableName(&Permission{})),
// 		perPage,
// 	)
// 	return
// }
